#ifndef __LOG_H__
#define __LOG_H__

#include <string>
#include <vector>
#include <stdarg.h>

#include "BaseThread/BaseThread.h"
#include "Poco/Net/DatagramSocket.h"

class Log : public BaseThread
{
public:
    Log();
    void InitFromConfig();
    void InitLogFile();

public:
    void SWarn(const char* fmt, ...);
    void SInfo(const char* fmt, ...);
    void SError(const char* fmt, ...);

    void UInfo(const char* fmt, ...);
    void UError(const char* fmt, ...);

public:
    void SetLogFileSize(int iMB);
    void SetLogFileCount(int iCount);
    void SetLogPath(std::string strPath);// default ./log

protected:
    virtual int SingleStep();

private:
    std::string VaList(const char* pHead, const char* fmt, va_list& ap);

private:
    void AddLog(std::string &strLog);

private:
    void SendUdp(std::string &strLog);

private:
    FILE* OpenNewLogFile();
    void CheckLogFile();
    std::vector<std::string> GetAllLogFIles();

private:
    Poco::Mutex m_mutexLog;
    std::vector<std::string> m_vectLog;

private:
    Poco::Mutex m_mutexUC;
    std::vector<Poco::Net::DatagramSocket> m_vectUdpClient;

private:
    int m_iLogFileSizeLimit;
    int m_iLogFileCount;
    std::string m_strLogPath;

private:
    bool m_bShowDate;
    bool m_bShowLevel;

private:
    std::vector<std::string> m_vectFilters;
};

extern Log zlog;

#endif//__LOG_H__
